package com.bbs.toutiao.controller.admin;


import cn.hutool.core.collection.CollUtil;
import com.bbs.toutiao.entity.CommentEntity;
import com.bbs.toutiao.service.admin.impl.CommentServiceImpl;
import com.bbs.toutiao.utils.Result;
import com.bbs.toutiao.vo.comm.PageVo;
import com.bbs.toutiao.vo.comment.ComResponseVo;
import com.bbs.toutiao.vo.comment.CommentPageRequestVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述: 评论控制类
 * 作者： zhangBin
 * 时间： 2023/9/26 18:03
 * 版本： 1.0
 */

@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Resource
    private CommentServiceImpl commentService;

    /**
     * 动态查询评论
     *
     * @param requestVo
     * @return
     */
    @PostMapping("/findByCommentPage")
    public Result getCommentPage(@RequestBody CommentPageRequestVo requestVo) {
        if (requestVo.getPage() < 1 || requestVo.getSize() < 1) {
            return Result.error(401, "请求的数据格式错误");
        }
        requestVo.setPage(requestVo.getPage(), requestVo.getSize());
        PageVo<ComResponseVo> commentPage = commentService.findByCommentPage(requestVo);
        return Result.success("查询成功", commentPage);
    }

    /**
     * 删除评论，服务端
     * @param comList
     * @return
     */
    @PostMapping("/deleteByIdComment")
    public Result deleteByIdComment(@RequestBody List<Map<String, Integer>> comList) {
//        log.info("需要删除的评论信息==>"+comList);
        if (CollUtil.isEmpty(comList)) {
            return Result.error(404,"要删除的属性不能为空");
        } else {
            int i= commentService.deleteByIdComment(comList);
            return Result.success("成功删除"+i+"条数据");
        }
    }
}
